package utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
  
public class FileUtil {
        public static void main(String[] args) throws IOException {
            FileInputStream is = null;
            FileOutputStream os = null;
            String formatName = "jpg";
            String iconName = "test.jpg";
            String tempPath = "C:/temp";
            String savePath = "C:/save";
            try {
                is = new FileInputStream(new File(tempPath + File.separator + iconName));
                os = new FileOutputStream(new File(savePath + File.separator + iconName));
                FileUtil.copyFile(is, os);
            }finally{
                    is.close();
                    os.close();
            }
        }
    
        public static void copyFile(InputStream is, OutputStream os) throws IOException{
            try {
                byte[] buff = new byte[8092];
                int len = -1;
                while((len = is.read(buff)) != -1){
                    os.write(buff, 0, len);
                }
            } finally {
                is.close();
                os.close();
            }
        }
}
